package org.smarthings.coap;

import org.eclipse.californium.core.CoapResponse;
import org.eclipse.californium.core.coap.CoAP.ResponseCode;

public class CoapUtil {
	public static int getHttpCode(CoapResponse response) {
		int coap = response.getCode().value;
		return ((int) (coap / 32)) * 100 + (coap % 32);
	}

	public static ResponseCode getCoapCode(int http, ResponseCode backup) {
		try {
			return ResponseCode.valueOf(((int) (http / 100)) * 32 + ((int) (http % 100)));
		} catch (IllegalArgumentException e) {
			return backup;
		}
	}
}
